package com.cn.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cn.pojo.AddressBook;
import com.cn.utils.AddressUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Date;
import java.util.List;
import java.util.Map;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cn.pojo.Orders;
import com.cn.mapper.OrdersMapper;
import com.cn.service.OrdersService;
@Service
public class OrdersServiceImpl extends ServiceImpl<OrdersMapper, Orders> implements OrdersService{

    @Autowired
    private OrdersMapper ordersMapper;
    @Override
    public Page<Orders> getOrdersList(String number, Integer status, String phone, String consignee, Page page) {
        List<Orders> ordersList=this.baseMapper.getOrdersList(number,status,phone,consignee,page);
        page.setRecords(ordersList);
        return page;
    }

    @Override
    public Orders selectAllById(Long id) {

        return ordersMapper.selectAllById(id);
    }

    @Override
    public Orders selectById(Long id) {
        Orders orders=this.baseMapper.selectById(id);
        List<Map<String, String>> list = AddressUtil.addressResolution(orders.getAddress());
        orders.setAddressProvince(list.get(0).get("addressProvince"));
        orders.setAddressCity(list.get(0).get("addressCity"));
        orders.setAddressTown(list.get(0).get("addressTown"));
        orders.setDetailAddress(list.get(0).get("detailAddress"));
        return orders;
    }


    @Override
    public int deleteOrders(Long id) {

        return this.baseMapper.deleteById(id);
    }

    @Override
    public Orders selectOrdersbyid(Long id) {

        return this.baseMapper.selectById(id);
    }

    @Override
    public int updateorder(Orders orders) {
        int i = this.baseMapper.updateById(orders);
        return i;
    }

    @Override
    public Integer updateAddress(Orders orders) {
        orders.setAddress(orders.getAddressProvince()+orders.getAddressCity()+orders.getAddressTown()+orders.getDetailAddress());
       return ordersMapper.updateById(orders);
    }

    @Override
    public Integer updateStatus(Orders orders) {
            orders.setStatus(5);
        return this.baseMapper.updateById(orders);
    }
}
